
#ifdef ECUT_MAIN
#include "TestRoad.h"
#include "util/EqualMatcher.h"

CPPUNIT_TEST_SUITE_REGISTRATION(TestRoad);


void TestRoad::setUp()
{
	aRoad = new Road("Abbey Road");
	oVertex = new Vertex("o");
	dVertex = new Vertex("d");
	oIntersection = new Intersection(2,3);
	dIntersection = new Intersection(2,3);
}
void TestRoad::testAddEdgeInNewSegments() {
	Edge edge1("1", oVertex, dVertex);
	Edge edge2("2", oVertex, dVertex);
	Edge edge3("3", oVertex, dVertex);
	aRoad->addEdge(&edge1, 100, 200, *oIntersection, *dIntersection);
	aRoad->addEdge(&edge2, 200, 300, *oIntersection, *dIntersection);
	aRoad->addEdge(&edge3, 300, 400, *oIntersection, *dIntersection);
	util::LinkedList<RoadSegment*>* segments = aRoad->getSegments();
	CPPUNIT_ASSERT(segments->count() == 3);
}

void TestRoad::testAddEdgeInSameSegment() {
	Edge edge1("1", oVertex, dVertex);
	Edge edge2("2", oVertex, dVertex);
	Edge edge3("3", oVertex, dVertex);
	aRoad->addEdge(&edge1, 100, 200, *oIntersection, *dIntersection);
	aRoad->addEdge(&edge2, 100, 200, *oIntersection, *dIntersection);
	aRoad->addEdge(&edge3, 100, 200, *oIntersection, *dIntersection);
	util::LinkedList<RoadSegment*>* segments = aRoad->getSegments();
	CPPUNIT_ASSERT(segments->count() == 1);
}

void TestRoad::testOverlapping() {
	Edge  edge1("1", oVertex, dVertex);
	Edge  edge2("2", oVertex, dVertex);
	aRoad->addEdge(&edge1, 100, 200, *oIntersection, *dIntersection);
	aRoad->addEdge(&edge2, 199, 300, *oIntersection, *dIntersection);
}

void TestRoad::testGetEdgesSimple() {
	Edge  edge1("1", oVertex, dVertex);
	Edge  edge2("2", oVertex, dVertex);
	Edge  edge3("3", oVertex, dVertex);
	aRoad->addEdge(&edge1, 100, 200, *oIntersection, *dIntersection);
	aRoad->addEdge(&edge2, 100, 200, *oIntersection, *dIntersection);
	aRoad->addEdge(&edge3, 000, 100, *oIntersection, *dIntersection);
	util::LinkedList<RoadSegment*>* segments = aRoad->getSegments(150);
	CPPUNIT_ASSERT(segments->count() == 1);
	CPPUNIT_ASSERT(segments->get(0)->getIncreasingEdges()->count() == 2);
	CPPUNIT_ASSERT(segments->get(0)->getDecreasingEdges()->count() == 0);
	EqualMatcher<Edge*> matcher;
	util::LinkedList<Edge*>* edges = segments->get(0)->getIncreasingEdges();
	CPPUNIT_ASSERT(edges->contains(matcher.setCurrent(&edge1)));
	CPPUNIT_ASSERT(edges->contains(matcher.setCurrent(&edge2)));
}

void TestRoad::testGetEdgesCorner() {
	Edge edge1("1", oVertex, dVertex);
	Edge edge2("2", oVertex, dVertex);
	Edge edge3("3", oVertex, dVertex);
	aRoad->addEdge(&edge1, 100, 200, *oIntersection, *dIntersection);
	aRoad->addEdge(&edge2, 200, 300, *oIntersection, *dIntersection);
	aRoad->addEdge(&edge3, 000, 100, *oIntersection, *dIntersection);
	util::LinkedList<RoadSegment*>* segments = aRoad->getSegments(200);
	CPPUNIT_ASSERT(segments->count() == 2);
	util::LinkedList<Edge*>* edges = new util::LinkedList<Edge*>();
	edges->pushAll(segments->get(0)->getIncreasingEdges());
	edges->pushAll(segments->get(1)->getIncreasingEdges());
	EqualMatcher<Edge*> matcher;
	CPPUNIT_ASSERT(edges->contains(matcher.setCurrent(&edge1)));
	CPPUNIT_ASSERT(edges->contains(matcher.setCurrent(&edge2)));
}

#endif /* ECUT_MAIN */

